import config from 'config'
import httpFetch from "share/httpFetch"
import errorMessage from "share/errorMessage";

export default {

  //获取单据查看列表
  getFinanceViewList(page, size,searchParams) {
    return httpFetch.post(`${config.baseUrl}/api/approvals/filters/get?size=${size}&page=${page}`,searchParams)
      .catch(e => {
        errorMessage(e.response);
        throw e;
      });
  },

  //获取表单类型
  //1001借款单，1002报销单，不传查全部
  getFormType(type){
    return httpFetch.get(`${config.baseUrl}/api/custom/forms/finance/all?formType=${type}`)
  },

  //导出单据列表
  exportFinanceList(searchParams) {
    let url = `${config.baseUrl}/api/reimbursement/batch/detail/export/expensReportOrApplication`;
    return httpFetch.post(url, searchParams, {}, {responseType: 'arraybuffer'});
  },

  printExpenseReport(expenseReportOID, settingObjects, isExpenseReportView){
    return httpFetch.get(`${config.baseUrl}/api/expense/reports/generate/pdf/${expenseReportOID}?settingObjects=${settingObjects}&isExpenseReportView=${isExpenseReportView}`);
  },

  //免打印查询
  searchPrintFree(tenantId,params) {
    return httpFetch.post(`${config.baseUrl}/config/api/config/hit/EXPENSE_REPORT_PRINT_FREE?tenantId=${tenantId}`, params);
  },

  //生成批次
  createBatch(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/expense/report/batch/create`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取批量下载列表
  getBatchList(params) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/expense/report/batch/get`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //生成pdf
  generatePDF(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/expense/reports/generate/pdf/batch/${id}?corporateFlag=true`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //下载批次
  downloadBatch(id) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/expense/report/batch/get/${id}`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //删除批次
  deleteBatch(id) {
    return new Promise((resolve, reject) => {
      httpFetch.delete(`${config.baseUrl}/api/expense/report/batch/delete/${id}`).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //获取批次号列表
  getBatchNumList(key) {
    return httpFetch.get(`${config.baseUrl}/api/expense/report/batch/get/fuzzy/${key}`)
  },

  getLoanBatchNumberList(key) {
    return httpFetch.get(`/api/loanBill/batch/get/fuzzy/${key}`)
  }

}
